/**
 * 
 */
package br.ufpi.util.notification;

import org.apache.commons.mail.EmailException;
import org.apache.commons.mail.HtmlEmail;

import br.ufpi.model.User;



/**
 * Enumeration notification mode
 * @author EasyTeam, created by Pedro Oliveira
 *
 */
public enum EnumNotificationMode {
	CEL_PHONE {
		@Override
		public boolean sendHTMLMessage(String subject, String msg, User toUser)
				throws EmailException {
			return false;
		}

		@Override
		public boolean sendMessage(String subject, String message, User toUser) throws Exception {
			/* Validate Phone Number */
			String phone = toUser.getTelefone().replace("(", "").replace(")", "").replace(" ", "").replace("-", "").trim();
			String name, msg = "";
			if(phone == null || phone.isEmpty()){
				return false;
			}
			if(message.length() > 160){				
				msg = message.substring(0, 159);
			}else{
				msg = message;
			}
			if(subject.length() > 11){
				name = subject.substring(0, 10);
			}else{
				name = subject;
			}
			SMS sms = new SMS(name, phone, msg);
			SMSUtil.sendSMS(sms);	
			return true;
		}

		@Override
		public boolean sendMessage(String subject, String msg, String name,
				String email_add) throws EmailException {
			return false;
		}


	}, TWITTER {
		@Override
		public boolean sendHTMLMessage(String subject, String msg, User toUser)
				throws EmailException {
			return false;
		}

		

		@Override
		public boolean sendMessage(String subject, String msg, String name,
				String email_add) throws EmailException {
			return false;
		}

		@Override
		public boolean sendMessage(String subject, String msg, User userFB)
				throws EmailException {
			return false;
		}

	}, EMAIL{
		@Override
		public boolean sendHTMLMessage(String subject, String msg, User toUser) throws EmailException {
			HtmlEmail email = new HtmlEmail();
			email.setHostName("smtp.gmail.com");
			email.setSSL(true);
			email.setSmtpPort(465);
			email.setAuthentication("contato-no-reply@infoway-pi.com.br", "cnt-n0t-r3ply");
			email.addTo(toUser.getLogin().getEmail(), toUser.getName());
			email.setFrom("contact@killline.com", "Kill Line Company");
			email.setSubject(subject);
			email.setCharset("utf-8");
			email.setHtmlMsg(msg);

			HtmlEmailUtil.sendEmail(email);

			return true;
		}

		@Override
		public boolean sendMessage(String subject, String msg, User toUser)	throws Exception {
			HtmlEmail email = new HtmlEmail();
			email.setHostName("smtp.gmail.com");
			email.setSSL(true);
			email.setSmtpPort(465);
			email.setAuthentication("contato-no-reply@infoway-pi.com.br", "cnt-n0t-r3ply");
			email.addTo(toUser.getLogin().getEmail(), toUser.getName());
			email.setFrom("contact@killline.com", "Kill Line Company");
			email.setSubject(subject);
			email.setMsg(msg);
			email.setCharset("utf-8");

			HtmlEmailUtil.sendEmail(email);

			return true;
		}
		
		@Override
		public boolean sendMessage(String subject, String msg, String name, String email_add)	throws EmailException {
			HtmlEmail email = new HtmlEmail();
			email.setHostName("smtp.gmail.com");
			email.setSSL(true);
			email.setSmtpPort(465);
			email.setAuthentication("contato-no-reply@infoway-pi.com.br", "cnt-n0t-r3ply");
			email.addTo(email_add, name);
			email.setFrom("contact@killline.com", "Kill Line Company");
			email.setSubject(subject);
			email.setMsg(msg);
			email.setCharset("utf-8");

			HtmlEmailUtil.sendEmail(email);

			return true;
		}
		

	};
	
	/**
	 * Send HTML Message
	 * @param subject
	 * @param msg
	 * @param toUser
	 * @return true if OK
	 * @throws EmailException
	 */
	public abstract boolean sendHTMLMessage(String subject, String msg, User toUser) throws EmailException;

	/**
	 * Send message
	 * @param subject
	 * @param msg
	 * @param toUser
	 * @return true if OK
	 * @throws EmailException
	 */
	public abstract boolean sendMessage(String subject, String msg, User toUser) throws Exception;
	
	/**
	 * Send message
	 * 
	 * @param subject
	 * @param msg
	 * @param name
	 * @param email_add
	 * @return true if OK
	 * @throws EmailException
	 */
	public abstract boolean sendMessage(String subject, String msg, String name, String email_add) throws EmailException;
	
	
	
}
